package com.example.myapplication.model;

import android.util.Log;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 数据库JDBC工具类
 */
public class MysqlJDBCUtil {

    private Connection cn;
    private Statement statement;

    /**
     * 连接数据库,获取sql语句执行对象
     */
    public Statement connectDb() {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            cn = DriverManager.getConnection("jdbc:mysql://localhost:3306/my", "root", "123456");
            // 创建用来执行sql语句的对象
            statement = cn.createStatement();
            // 执行sql查询语句并获取查询信息
//            ResultSet rSet = statement.executeQuery(sql);
        } catch (Exception e) {
            e.printStackTrace();
            Log.i("db", "connectDb: "+e);
        }
        return statement;
    }

}
